<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>注册</title>
    <link rel="stylesheet" type="text/css" href="../style/api.css" />
    <link rel="stylesheet" type="text/css" href="../style/head.css" />
    <style>
        html,
        body {
            background-color: #fff;
        }

        #closeIt {
            position: absolute;
            top: 35px;
            left: 1rem;
            width: 2rem;
            height: 2rem;
        }

        main {
            padding-top: 75px;
        }

        .login-title {
            color: #3949AB;
            padding: 0.5rem;
        }

        .login-title h3 {
            margin: 0.3rem 0;
        }

        .login-box {
            padding: 0.5rem;
        }

        .login-box div {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 1rem;
        }

        .login-box div img {
            width: 1.5rem;
            height: 1.5rem;
        }

        .login-box div input {
            width: 90%;
            padding: 1rem;
            outline: none;
        }

        .login {
            color: #DDC72B;
            margin-left: 1rem;
            padding: 1rem 2rem;
            border-radius: 0.4rem;
            background-color: #3949AB;
        }

        .noCount {
            color: #999;
            margin-left: 5rem;
        }

        .noCount i {
            color: #101010;
            font-style: normal;
            text-decoration: underline;
        }
    </style>
</head>

<body>
    <header>
        注册
        <img src="../img/icons/back.png" alt="" onclick="api.closeWin()" id="closeIt">
    </header>
    <main>
        <div class="login-title">
            <h3>你好！</h3>
            <p>欢迎注册，让你更懂区块链</p>
        </div>
        <div class="login-box">
            <div>
                <img src="../img/icons/userlogo.png" alt="">
                <input type="text" placeholder="输入用户名" id="uname">
            </div>
            <div>
                <img src="../img/icons/password.png" alt="">
                <input type="password" placeholder="输入密码" id="pwd">
            </div>
            <div>
                <img src="../img/icons/password.png" alt="">
                <input type="password" placeholder="输入密码" id="pwd2">
            </div>
            <span class="login">注册</span>
            <span class="noCount">注册即代表同意<i>《隐私协议》</i></span>
        </div>
    </main>
</body>
<script type="text/javascript" src="../js/api.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript">
    apiready = function() {

    };

    $('.login').click(function() {
        var uname = $('#uname').val();
        var pwd = $('#pwd').val();
        var pwd2 = $('#pwd2').val();

        if (!uname || $.trim(uname).length == 0) {
            api.toast({
                msg: '未输入用户名',
                duration: 2000,
                location: 'bottom'
            });
            return
        };
        if (!pwd || $.trim(pwd).length == 0) {
            api.toast({
                msg: '未输入密码',
                duration: 2000,
                location: 'bottom'
            });
            return
        };
        if (!pwd2 || $.trim(pwd2).length == 0) {
            api.toast({
                msg: '请确认密码',
                duration: 2000,
                location: 'bottom'
            });
            return
        };
        if (pwd != pwd2) {
            api.toast({
                msg: '前后输入密码不一致',
                duration: 2000,
                location: 'bottom'
            });
            return
        };
        api.ajax({
            url: 'http://114.116.243.15/newbtb/appinfo/queryUser.lecture',
            method: 'post',
            data: {
                body: {
                  'btb_data': {
                      'lecture_username': uname,
                  }
                }
            }
        },function(ret, err){
            if (ret) {
                if (ret.btb_data.total == 1) {
                  api.toast({
                      msg: '该用户名已被注册',
                      duration: 2000,
                      location: 'bottom'
                  });
                }
                else {
                  api.ajax({
                      url: 'http://114.116.243.15/newbtb/appinfo/signup.lecture',
                      method: 'post',
                      data: {
                          body: {
                              'tbname': 'lecture_user',
                              "lecture_username": uname,
                              "lecture_password": pwd,
                          }
                      }
                  },function(ret, err){
                      if (ret) {
                          if(ret.status == 1) {
                              api.toast({
                                  msg: '注册成功',
                                  duration: 2000,
                                  location: 'bottom'
                              });
                              $('#uname').val('');
                              $('#pwd').val('');
                              $('#pwd2').val('');
                              setTimeout(function(){
                                api.closeWin({
                                    name: 'signup'
                                });
                              },1000);
                          }
                      }
                  });

                }
            }
        });
    })

    $('.noCount').click(function() {
        api.openWin({
            name: 'privacy',
            url: './btb-privacy.html',
        });
    })
</script>

</html>
